package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class saveDoc_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.List _jspx_dependants;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n");
      out.write("<html>\n");
      out.write("<head>\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n");
      out.write("<title></title>\n");
      out.write("</head>\n");
      out.write("<body>\n");

	BinaryReader bReader = new BinaryReader(Request.InputStream);
  	string strTemp = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(
  	bReader.ReadBytes((int)bReader.BaseStream.Length), 0, (int)bReader.BaseStream.Length);
  	string match = "Content-Type: application/msword\r\n\r\n";
  	int pos = strTemp.IndexOf(match) + match.Length;
  	bReader.BaseStream.Seek(pos, SeekOrigin.Begin);

 	 string newFile = Server.MapPath(".") + "\\MyFile2.doc";
  	FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write);
  	BinaryWriter bWriter = new BinaryWriter(newDoc);
  	bWriter.BaseStream.Seek(0, SeekOrigin.End);


 	 while (bReader.BaseStream.Position < bReader.BaseStream.Length - 38)
 	 bWriter.Write(bReader.ReadByte());

 	bReader.Close();
 	 bWriter.Flush();
  	bWriter.Close();

      out.write("\n");
      out.write("</body>\n");
      out.write("</html>\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
